package main

import (
	"crypto"
	"fmt"
	certuitl "./cert"
	"time"
)

func createSigningCertKey(prefix, certFile, keyFile string) (bool, error) {
	//if exists(certFile, keyFile) {
	//	return false, nil
	//}

	caKeyBytes, _, err := certuitl.LoadOrGenerateKeyFile(keyFile, false)
	if err != nil {
		return false, err
	}

	caKey, err := certuitl.ParsePrivateKeyPEM(caKeyBytes)
	if err != nil {
		return false, err
	}

	cfg := certuitl.Config{
		CommonName: fmt.Sprintf("%s-ca@%d", prefix, time.Now().Unix()),
	}

	cert, err := certuitl.NewSelfSignedCACert(cfg, caKey.(crypto.Signer))
	if err != nil {
		return false, err
	}

	if err := certuitl.WriteCert(certFile, certuitl.EncodeCertPEM(cert)); err != nil {
		return false, err
	}
	return true, nil
}

func main() {
	createSigningCertKey("SKE-server", "ecdsa.crt", "ecdsa.key")
}


